package ch.rheintalconnection.sysventory.application;

import java.util.List;

import org.apache.commons.net.util.SubnetUtils;

import ch.rheintalconnection.sysventory.businessServices.ScanningService;
import ch.rheintalconnection.sysventory.domain.Scan;
import ch.rheintalconnection.sysventory.domain.ScanEntry;
import ch.rheintalconnection.sysventory.domain.User;

public class ScanCommand {

	private ScanningService scanningService;
	
	public ScanCommand(ScanningService scanningService){
		this.scanningService = scanningService;
	}
	
	// Returns the count of scanned Computers
	public int scan(String sIpMask, User user){
		
		Scan scan = scanningService.scanAndStore(sIpMask, user);
		List<ScanEntry> scanEntries = scan.getScanEntries();
		
		return scanEntries.size();
	}
	
	//TODO Jonas do kasch d IpMask validiere
	public boolean validateIpMask(String sIpMask){
		
		try {
			new SubnetUtils(sIpMask);
			return true;
			
		} catch (IllegalArgumentException e) {
			return false;
		}
		
	}
	
}
